docs(guide): 添加 ContextAware 生成器文档并更新相关链接#86
Conversation
- 新增 ContextAware 生成器完整文档,介绍自动实现 IContextAware 接口的功能 - 更新索引页面中的相关链接,替换规则生成器为 ContextAware 生成器 - 修改基础使用示例中的命名空间引用和代码实现细节 - 补充测试场景配置和多架构场景的使用说明 - 添加最佳实践和诊断信息相关内容
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 7, 2026 3:13p.m. | Review ↗ | |
| Secrets | Mar 7, 2026 3:13p.m. | Review ↗ |
Reviewer's Guide为新的 ContextAware 源代码生成器补充了完整文档,更新了主源代码生成器文档以使用它替代旧的规则生成器,并刷新了基础用法示例和生成代码,使其匹配新的 IContextAware 模式,包括上下文提供程序配置以及测试指南。 使用默认 GameContextProvider 惰性初始化 Context 的时序图sequenceDiagram
actor Game
participant PlayerController
participant GameContextProvider
participant IArchitectureContext
Game->>PlayerController: Initialize()
PlayerController->>PlayerController: access Context
alt _context is null and _contextProvider is null
PlayerController->>GameContextProvider: new GameContextProvider()
PlayerController->>GameContextProvider: GetContext()
GameContextProvider-->>PlayerController: IArchitectureContext
PlayerController->>PlayerController: cache in _context
else _context already set
PlayerController->>PlayerController: reuse _context
end
PlayerController->>IArchitectureContext: GetModel PlayerModel
IArchitectureContext-->>PlayerController: PlayerModel
PlayerController->>IArchitectureContext: GetSystem CombatSystem
IArchitectureContext-->>PlayerController: CombatSystem
PlayerController->>IArchitectureContext: SendEvent PlayerInitializedEvent
测试配置覆盖 Context 提供程序的时序图sequenceDiagram
actor TestRunner
participant TestMethod
participant PlayerController
participant TestContextProvider
participant IArchitectureContext
TestRunner->>TestMethod: execute TestPlayerController
TestMethod->>TestMethod: create TestArchitecture
TestMethod->>TestContextProvider: new TestContextProvider(testArchitecture)
TestMethod->>PlayerController: SetContextProvider(provider)
TestMethod->>PlayerController: new PlayerController()
TestMethod->>PlayerController: Initialize()
PlayerController->>PlayerController: access Context
alt _context is null and _contextProvider already set
PlayerController->>TestContextProvider: GetContext()
TestContextProvider-->>PlayerController: IArchitectureContext
PlayerController->>PlayerController: cache in _context
else _context already set
PlayerController->>PlayerController: reuse _context
end
PlayerController->>IArchitectureContext: GetModel PlayerModel
IArchitectureContext-->>PlayerController: PlayerModel
TestMethod-->>TestRunner: assertions and finally ResetContextProvider
ContextAware 生成模式及相关抽象的类图classDiagram
class PlayerController {
-_context : IArchitectureContext
-_contextProvider : IArchitectureContextProvider
+PlayerController()
+Initialize() void
+Attack(target : Enemy) void
+static SetContextProvider(provider : IArchitectureContextProvider) void
+static ResetContextProvider() void
#Context : IArchitectureContext
}
class IContextAware {
<<interface>>
+SetContext(context : IArchitectureContext) void
+GetContext() IArchitectureContext
}
class IController {
<<interface>>
}
class IArchitectureContext {
<<interface>>
+GetModel_T_() T
+GetSystem_T_() T
+GetUtility_T_() T
+SendEvent(event : object) void
+SendCommand(command : object) void
}
class IArchitectureContextProvider {
<<interface>>
+GetContext() IArchitectureContext
}
class GameContextProvider {
+GameContextProvider()
+GetContext() IArchitectureContext
}
class TestContextProvider {
-architecture : IArchitecture
+TestContextProvider(architecture : IArchitecture)
+GetContext() IArchitectureContext
}
class IArchitecture {
<<interface>>
}
PlayerController ..|> IController
PlayerController ..|> IContextAware
GameContextProvider ..|> IArchitectureContextProvider
TestContextProvider ..|> IArchitectureContextProvider
IArchitectureContextProvider --> IArchitectureContext
TestContextProvider --> IArchitecture : wraps
PlayerController --> IArchitectureContext : uses_Context
PlayerController --> IArchitectureContextProvider : uses_contextProvider
文件级变更
Tips and commandsInteracting with Sourcery
Customizing Your Experience访问你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdds comprehensive documentation for the new ContextAware source generator, updates the main source generator docs to use it instead of the old rule generator, and refreshes the basic usage example and generated code to match the new IContextAware pattern with context provider configuration and testing guidance. Sequence diagram for lazy Context initialization with default GameContextProvidersequenceDiagram
actor Game
participant PlayerController
participant GameContextProvider
participant IArchitectureContext
Game->>PlayerController: Initialize()
PlayerController->>PlayerController: access Context
alt _context is null and _contextProvider is null
PlayerController->>GameContextProvider: new GameContextProvider()
PlayerController->>GameContextProvider: GetContext()
GameContextProvider-->>PlayerController: IArchitectureContext
PlayerController->>PlayerController: cache in _context
else _context already set
PlayerController->>PlayerController: reuse _context
end
PlayerController->>IArchitectureContext: GetModel PlayerModel
IArchitectureContext-->>PlayerController: PlayerModel
PlayerController->>IArchitectureContext: GetSystem CombatSystem
IArchitectureContext-->>PlayerController: CombatSystem
PlayerController->>IArchitectureContext: SendEvent PlayerInitializedEvent
Sequence diagram for test configuration overriding Context providersequenceDiagram
actor TestRunner
participant TestMethod
participant PlayerController
participant TestContextProvider
participant IArchitectureContext
TestRunner->>TestMethod: execute TestPlayerController
TestMethod->>TestMethod: create TestArchitecture
TestMethod->>TestContextProvider: new TestContextProvider(testArchitecture)
TestMethod->>PlayerController: SetContextProvider(provider)
TestMethod->>PlayerController: new PlayerController()
TestMethod->>PlayerController: Initialize()
PlayerController->>PlayerController: access Context
alt _context is null and _contextProvider already set
PlayerController->>TestContextProvider: GetContext()
TestContextProvider-->>PlayerController: IArchitectureContext
PlayerController->>PlayerController: cache in _context
else _context already set
PlayerController->>PlayerController: reuse _context
end
PlayerController->>IArchitectureContext: GetModel PlayerModel
IArchitectureContext-->>PlayerController: PlayerModel
TestMethod-->>TestRunner: assertions and finally ResetContextProvider
Class diagram for ContextAware generated pattern and related abstractionsclassDiagram
class PlayerController {
-_context : IArchitectureContext
-_contextProvider : IArchitectureContextProvider
+PlayerController()
+Initialize() void
+Attack(target : Enemy) void
+static SetContextProvider(provider : IArchitectureContextProvider) void
+static ResetContextProvider() void
#Context : IArchitectureContext
}
class IContextAware {
<<interface>>
+SetContext(context : IArchitectureContext) void
+GetContext() IArchitectureContext
}
class IController {
<<interface>>
}
class IArchitectureContext {
<<interface>>
+GetModel_T_() T
+GetSystem_T_() T
+GetUtility_T_() T
+SendEvent(event : object) void
+SendCommand(command : object) void
}
class IArchitectureContextProvider {
<<interface>>
+GetContext() IArchitectureContext
}
class GameContextProvider {
+GameContextProvider()
+GetContext() IArchitectureContext
}
class TestContextProvider {
-architecture : IArchitecture
+TestContextProvider(architecture : IArchitecture)
+GetContext() IArchitectureContext
}
class IArchitecture {
<<interface>>
}
PlayerController ..|> IController
PlayerController ..|> IContextAware
GameContextProvider ..|> IArchitectureContextProvider
TestContextProvider ..|> IArchitectureContextProvider
IArchitectureContextProvider --> IArchitectureContext
TestContextProvider --> IArchitecture : wraps
PlayerController --> IArchitectureContext : uses_Context
PlayerController --> IArchitectureContextProvider : uses_contextProvider
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了 1 个问题,并给出了一些整体性的反馈:
- 生成的代码示例使用了
global::GFramework.Core.architecture.GameContextProvider,而相关接口位于GFramework.Core.Abstractions.architecture命名空间下;请再次确认GameContextProvider的命名空间,以避免示例产生混淆或错误。 - 在新的
context-aware-generator.md示例中,测试方法TestPlayerController被声明为void,但方法体中使用了await;请将方法签名更新为public async Task TestPlayerController()(或者去掉await),以确保示例可以编译,并与索引页中的示例保持一致。 - 新的
context-aware-generator.md在底部“相关文档”部分仍然链接到./rule-generator,但本 PR 中已经移除了rule-generator.md文件,同时在“何时继承 ContextAwareBase”一节中存在一处乱码("需要生命���期管理");请考虑修复损坏的链接并更正该错别字。
供 AI Agent 使用的提示词
请根据本次代码审查中的评论进行修改:
## 整体评论
- 生成的代码示例使用了 `global::GFramework.Core.architecture.GameContextProvider`,而相关接口位于 `GFramework.Core.Abstractions.architecture` 命名空间下;请再次确认 `GameContextProvider` 的命名空间,以避免示例产生混淆或错误。
- 在新的 `context-aware-generator.md` 示例中,测试方法 `TestPlayerController` 被声明为 `void`,但方法体中使用了 `await`;请将方法签名更新为 `public async Task TestPlayerController()`(或者去掉 `await`),以确保示例可以编译,并与索引页中的示例保持一致。
- 新的 `context-aware-generator.md` 在底部“相关文档”部分仍然链接到 `./rule-generator`,但本 PR 中已经移除了 `rule-generator.md` 文件,同时在“何时继承 ContextAwareBase”一节中存在一处乱码("需要生命���期管理");请考虑修复损坏的链接并更正该错别字。
## 单条评论
### 评论 1
<location path="docs/zh-CN/source-generators/context-aware-generator.md" line_range="235-236" />
<code_context>
+如果类需要更多框架功能(如生命周期管理),应继承 `ContextAwareBase`:
+
+```csharp
+// 推荐:需要生命���期管理时继承基类
+public class PlayerModel : AbstractModel
+{
</code_context>
<issue_to_address>
**issue (typo):** “生命���期管理”存在明显乱码,应为“生命周期管理”。
注释中的“生命���期管理”应更正为“生命周期管理”,以避免读者产生困惑。
```suggestion
// 推荐:需要生命周期管理时继承基类
public class PlayerModel : AbstractModel
```
</issue_to_address>帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The generated code samples use
global::GFramework.Core.architecture.GameContextProviderwhile the related interfaces live underGFramework.Core.Abstractions.architecture; double-check the namespace forGameContextProviderto avoid confusing or incorrect examples. - In the new
context-aware-generator.mdexamples, the test methodTestPlayerControlleris declared asvoidbut usesawaitinside; update the signature topublic async Task TestPlayerController()(or removeawait) to keep the sample compilable and consistent with the index example. - The new
context-aware-generator.mdstill links to./rule-generatorat the bottom under “相关文档” even thoughrule-generator.mdis removed in this PR, and there is also a garbled phrase in “何时继承 ContextAwareBase” ("需要生命���期管理"); consider fixing the broken link and the typo.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The generated code samples use `global::GFramework.Core.architecture.GameContextProvider` while the related interfaces live under `GFramework.Core.Abstractions.architecture`; double-check the namespace for `GameContextProvider` to avoid confusing or incorrect examples.
- In the new `context-aware-generator.md` examples, the test method `TestPlayerController` is declared as `void` but uses `await` inside; update the signature to `public async Task TestPlayerController()` (or remove `await`) to keep the sample compilable and consistent with the index example.
- The new `context-aware-generator.md` still links to `./rule-generator` at the bottom under “相关文档” even though `rule-generator.md` is removed in this PR, and there is also a garbled phrase in “何时继承 ContextAwareBase” ("需要生命���期管理"); consider fixing the broken link and the typo.
## Individual Comments
### Comment 1
<location path="docs/zh-CN/source-generators/context-aware-generator.md" line_range="235-236" />
<code_context>
+如果类需要更多框架功能(如生命周期管理),应继承 `ContextAwareBase`:
+
+```csharp
+// 推荐:需要生命���期管理时继承基类
+public class PlayerModel : AbstractModel
+{
</code_context>
<issue_to_address>
**issue (typo):** “生命���期管理”存在明显乱码,应为“生命周期管理”。
注释中的“生命���期管理”应更正为“生命周期管理”,以避免读者产生困惑。
```suggestion
// 推荐:需要生命周期管理时继承基类
public class PlayerModel : AbstractModel
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 修复了代码注释中的错别字"生命期"为"生命周期" - 移除了文档末尾的规则验证生成器链接引用
- 将 TestPlayerController 方法从同步改为异步 - 使用 Task 类型替代 void 返回类型 - 为测试方法添加 async 关键字修饰符
- 移除 .claude 设置文件 - 重构枚举扩展生成器文档,更新 API 使用方式和配置选项 - 调整日志生成器文档,更新属性使用方式和配置参数 - 修改 Git 忽略规则添加 .claude/settings.json - 更新代码示例和最佳实践指南
由 Sourcery 提供的摘要
为新的 ContextAware 源生成器撰写文档,并更新相关文档中的引用和示例以使用该生成器。
文档更新内容:
Original summary in English
Summary by Sourcery
Document the new ContextAware source generator and update related documentation references and examples to use it.
Documentation: